<template lang="html">
  <div id="charts">
    <div id="bm" :style="{width:'100%',height:'100%'}"></div>
  </div>
</template>

<script>
import * as Util from '../../../Util'
import co from 'co'
import echarts from 'echarts'
import {HttpResetClass } from 'vue-client'

let getData = function * (self) {
  let load = new HttpResetClass()
  load.load('POST', 'rs/sql/sellinggasvalue',
  {data: {startDate: self.startdate, endDate: self.enddate, key: 'f_bank_name'}},
  {resolveMsg: null, rejectMsg: null})
  .then((res) => {
    self.texttile = '用户类型'
    let arrparams = []
    let numdata = []
    let gasdata = []
    let pricedata = []
    for (var i = 0; i < res.data.length; i++) {
        arrparams[i] = res.data[i].name
        numdata[i] = res.data[i].num_value
        gasdata[i] = res.data[i].gas_value
        pricedata[i] = res.data[i].money_value
    }
    self.set(arrparams,numdata,gasdata,pricedata)
  })
}
export default {
  props: {
    startdate: {
    type: String,
    default: Util.toStandardDateString()
  },
  enddate: {
    type: String,
    default: Util.toStandardDateString()
  }
},
 data () {
   title: '银行管理'
   return {
     texttile: '',
     xc: ''
   }
 },
 methods: {
   set (arrparams,numdata,gasdata,pricedata) {
     this.xc = echarts.init(document.getElementById('bm'))
     this.xc.setOption({
       title : {
         text: '银行代售气量金额散列图',
         subtext: '数据查询来源',
         x: 'left'
       },
       tooltip : {
         trigger: 'axis'
       },
       legend: {
         x: 'left',
         y: 'bottom',
         data: ['数量','气量','金额']
       },
       toolbox: {
         show : true,
         feature : {
           dataView : {show: true, readOnly: false},
           magicType : {show: true, type: ['line', 'bar']},
           restore : {show: true},
           saveAsImage : {show: true}
         }
       },
       calculable : true,
       xAxis : [
         {
           type : 'category',
           data : arrparams
         }
      ],
      yAxis : [
        {
          type : 'value'
        }
      ],
      series : [
        {
          name:'数量',
          type:'bar',
          data:numdata,
          markLine : {
            data : [
              {type : 'average', name: '平均值'}
            ]
          }
        },
        {
          name:'气量',
          type:'bar',
          data:gasdata,
          markLine : {
            data : [
              {type : 'average', name: '平均值'}
            ]
          }
        },
        {
          name:'金额',
          type:'bar',
          data:pricedata,
          markLine : {
          data : [
              {type : 'average', name : '平均值'}
            ]
          }
        }
      ]
     })
   },
   searchdata () {
     let getGen =getData(this)
     co(getGen)
   }
 },
 ready () {
   this.searchdata()
 },
 watch: {
   'startdate' (val) {
     this.searchdata()
   },
   'enddate' (val) {
     this.searchdata()
   }
 }

}
</script>
